<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: YanHilin
  Date: 2020/5/14
  Time: 9:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>鲜花产品详情</title>
    <base href="http://localhost:8080/onlineflower/">
    <%@include file="/page/comment/head.jsp" %>
    <style type="text/css">
        .center {
            width: 80%;
            margin: auto auto;
            margin-bottom: 20px;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }

        .left {
            width: 30%;
            margin-top: 13px;
            height: 400px;
        }

        .left img {
            width: 100%;
            height: 100%;
        }

        .right {
            margin-top: 13px;
        }

        .right a {
            text-align: center;
            font-size: 23px;
        }

        .right .intrduction {
            height: 150px;
        }

        .right p {
            font-size: 18px;
            padding: 10px 0;
            color: gray;
        }

        .right .section {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            margin-top: 20px;
            margin-bottom: 5px;
        }

        #showEvaluate {
            width: 80%;
            margin: auto auto;
        }

        #evaluate {
            width: 80%;
            margin: auto auto;
        }

        #price {
            color: red;
            font-size: 23px;
        }

        #price_code {
            font-size: 27px;
        }
    </style>
</head>
<body>

<div class="center">
    <c:forEach items="${requestScope.flowers}" var="item">
        <div class="left">
            <img src="static/picFlower/${item.flower_photo}" class="card-img" alt="图片">
            <div class="enter"></div>
        </div>
        <div class="right">
            <a href="">${item.enterprise_name}</a>
            <h3 class="card-title">${item.flower_name}</h3>
            <br>
            <div class="intrduction">
                <具体介绍>&nbsp;<br/>
                    <span style="letter-spacing: 2px;padding: 2px">${item.introduce}</span>
            </div>
            <p class="card-text">库存：${item.stock} &nbsp;&nbsp; 销量：${item.sales} &nbsp;&nbsp;鲜花类别：${item.fclassname}</p>
            <div class="section">
                <span class="card-title" id="price_code">￥<span id="price">${item.price}
                <button flowerid="${item.flowerid}" class="cart input-lg">Cart <span
                        class="glyphicon glyphicon-shopping-cart"></span></button>
                <button class="showEvaluate input-lg" flowerid="${item.flowerid}">显示评论</button>
                   <%-- <button flowerid="${item.flowerid}" class="collect input-lg">收藏
                        <svg class="bi bi-heart" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor"
                             xmlns="http://www.w3.org/2000/svg">
                            <path fill-rule="evenodd"
                                  d="M8 2.748l-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z"
                                  clip-rule="evenodd"/>
                        </svg>
                    </button>&nbsp;--%>
            </div>
        </div>
    </c:forEach>
</div>
<div id="evaluate" class="evaluate"></div>
</body>
<script src="static/js/jquery-3.4.1.js"></script>
<script>
    $(function () {
        $("button.cart").click(function () {
            var flowerid = $(this).attr("flowerid");
            location.href = "http://localhost:8080/onlineflower/cartServlet?action=addItem&id=" + flowerid;
        });
        $("button.showEvaluate").click(function () {
            var flowerid = $(this).attr("flowerid");
            console.log(flowerid);
            $.getJSON("http://localhost:8080/onlineflower/evaluateServlet?action=showEvaluate&flowerid=" + flowerid, function (data) {
                $.each(data.evaluates, function (index, item) {
                    console.log(item["id"]);
                    html = "<div class=\"card\">" + " <div class=\"card-header\">" + item["userid"]
                        + "</div><div class=\"card-body\">" +
                        "<blockquote class=\"blockquote mb-0\"><p>" + item["content"] + "</p></blockquote>"
                        + "</div> <div class=\"card-footer\">" + item["createtime"] + "</div></div></br/>";
                    $(".evaluate").append(html);
                })
            })
        });
        $("button.collect").click(function () {
            var flowerid = $(this).attr("flowerid");
            location.href = "http://localhost:8080/onlineflower/collectServlet?action=add&id=" + flowerid;
        });
    })
</script>
</html>
